﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FrameWork.web.Code;
using FrameWork.Entity;

namespace FrameWork.web.Module.ITMS.Service
{
    public partial class UserSelect1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["SelectUser"] = null;
                //绑定报修人部门
                sys_Group sg = new sys_Group();
                its_GroupCs sgCs = new its_GroupCs();
                DataTable dtGroup = sgCs.Group_SelectInfo(sg);
                this.drpGroup.DataTextField = "G_CName";
                this.drpGroup.DataValueField = "GroupID";
                this.drpGroup.DataSource = dtGroup;
                this.drpGroup.DataBind();
            }
        }

        protected void btnSeach_Click(object sender, EventArgs e)
        {
            sys_User su = new sys_User();
            su.U_CName = this.txt_CName.Text.Trim();
            su.U_GroupID = int.Parse(this.drpGroup.SelectedValue);
            su.U_UserNO = this.txt_UserNO.Text.Trim();
            //根据条件查找用户
            sys_UserCs suCs = new sys_UserCs();
            DataTable dt = suCs.User_SelectInfoByU_CNameAndU_GroupIDAndU_UserNO(su);
            this.lbUser.DataTextField = "U_DESC";
            this.lbUser.DataValueField = "UserID";
            this.lbUser.DataSource = dt;
            this.lbUser.DataBind();
           
            //缓存查询结果
            Session["SelectUser"] = dt;
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (this.lbUser.SelectedIndex == -1)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "NotChoose", "<script>alert('请选择一个用户！');</script>");
                return;
            }
            DataTable dt=Session["SelectUser"] as DataTable;
            DataRow[] dr = dt.Select("UserID=" + this.lbUser.SelectedItem.Value);
            //string strResult = this.lbUser.SelectedItem.Text + "," + this.lbUser.SelectedItem.Value;
            string strResult = Server.HtmlEncode(dr[0]["U_CName"].ToString()) + "," + dr[0]["UserID"].ToString() + "," + dr[0]["U_UserNO"].ToString() + "," + dr[0]["U_GroupID"].ToString() + "," + dr[0]["U_Extension"].ToString();
            this.ClientScript.RegisterStartupScript(this.GetType(), "Return", "<script>back('" + strResult + "');</script>");
            Session["SelectUser"] = null;
        }
    }
}
